#include "lib_fixed.h"

fixed::fixed(const char *s)
{
    value     = 0;
    precision = 0;
    int  c;
    while ((c = *s++) == ' ' || c == '\t') ;
    bool negative;
    if (c == '-')
    {
        negative = true;
        c        = *s++;
    }
    else
        negative = false;
    bool decimal = false;
    while (precision < MAX_FIXED_PRECISION)
    {
        if ('0' <= c && c <= '9')
        {
            value = value * 10 + (c - '0');
            if (decimal)
                precision++;
        }
        else if (c == '.')
        {
            if (decimal)
                break;
            decimal = true;
        }
        else if (c != ',')
            break;
        c = *s++;
    }
    if (negative)
        value = -value;
}

